#/bin/bash
HOST=("im.example.cn" "www.example.com")
PORT="443"
for url in "${HOST[@]}"
do
  # 获取证书信息
	cert_info=$(echo | openssl s_client -servername $url -connect $url:$PORT 2>/dev/null | openssl x509 -noout -dates)
	# 提取证书有效期的起止日期
	start_date=$(echo "$cert_info" | grep -i "notBefore" | awk -F '=' '{print $2}')
	end_date=$(echo "$cert_info" | grep -i "notAfter" | awk -F '=' '{print $2}')
	# 将日期转换为时间戳
	start_timestamp=$(date -d "$start_date" +%s)
	end_timestamp=$(date -d "$end_date" +%s)
	current_timestamp=$(date +%s)
	# 计算剩余天数
	remaining_days=$(( ($end_timestamp - $current_timestamp) / 86400 ))
	# 打印证书有效期信息
	echo "域名: $url 起始日期: $start_date 结束日期: $end_date 剩余天数: $remaining_days"
done



